import Web3 from 'web3'
import crypto from 'crypto'

const QUICKNODE_RPC_URL ='https://bsc-dataseed.binance.org/' // BSC 主网 RPC 节点

async function main(){
    // const address = '0x32BC9D4f47E5e3A22C8f04301d3f4Ea7aE2F9905';//b00 zf
    const address = '0x833D5D0375D4D068E9A1684a6D5E41079482F029';//b01 zf
    encodeSeo(address);

    // createWallet(10);
}

/**
 * 增发钱包编码
 * @param {*} address 
 * @returns 
 */
  const encodeSeo= (address) => {
  // 编码地址（注意：encodePacked 会将地址按原样编码为字节数组）
  const addressBytes = Buffer.from(address.slice(2), 'hex');
  const hash = crypto.createHash('sha256').update(addressBytes).digest();
  const encode='0x' + hash.toString('hex');
  console.log(`增发地址: ${address} \n地址加密: ${encode}`);
  return encode;
}

const initWeb3 = async () => {
  const web3 = new Web3(QUICKNODE_RPC_URL);
  return web3;
}

 const createWallet = async(num) => {
    const web3 = await initWeb3();
    for(let i=0;i<num;i++){
      const account = web3.eth.accounts.create()
      console.info(`\n地址: ${account.address}`);
      console.info(`私钥: ${account.privateKey}`);
    }
}

main();